package com.lancoo.znbkxx.teacher.ui.fragment.cognitiveAssessment

import android.view.View
import androidx.viewpager.widget.ViewPager

/*
* viewpager缩放类
* */
class DepthPageTransformer : ViewPager.PageTransformer {
    override fun transformPage(view: View, position: Float) {
        /**
         * 过滤那些 <-1 或 >1 的值，使它区于【-1，1】之间
         */
        var position = position
        if (position < -1) {
            position = -1f
        } else if (position > 1) {
            position = 1f
        }
        /**
         * 判断是前一页 1 + position ，右滑 pos -> -1 变 0
         * 判断是后一页 1 - position ，左滑 pos -> 1 变 0
         */
        val tempScale = if (position < 0) 1 + position else 1 - position // [0,1]
        val scaleValue = MIN_SCALE + tempScale * 0.1f // [0,1]
        view.scaleX = scaleValue
        view.scaleY = scaleValue
    }

    companion object {
        /*
    * viewpager缩放效果
    * */
        private const val MIN_SCALE = 0.9f
    }
}